package com.imelite.qyh.action;

import com.imelite.qyh.data.NPS_Bean;
import com.imelite.qyh.data.util.NPS_Util;
import com.imelite.qyh.model.EliteCRMView_dcwj;
import com.imelite.qyh.service.EliteCRMView_dcwjService;
import com.imelite.qyh.util.BaseDateUtil;
import com.imelite.qyh.util.BaseStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@Controller
public class NPSAction {

    @Autowired
    private EliteCRMView_dcwjService eliteCRMView_dcwjService;

    @RequestMapping("/com/imelite/qyh/NPSAction/get_NPSTotoal")
    public String get_NPSTotoal(HttpServletRequest request, HttpServletResponse response, EliteCRMView_dcwj dcwj){
        if(BaseStringUtil.isBlank(dcwj.getYear())){
            String year= BaseDateUtil.getFormatString(new Date(),"yyyy");
            dcwj.setYear(year);
        }

        if(BaseStringUtil.isBlank(dcwj.getQuarter())){
            dcwj.setQuarter("1");
        }
        dcwj.setNotnull(true);
        List<EliteCRMView_dcwj> dcwjList = eliteCRMView_dcwjService.selectByForm(dcwj);
        List<NPS_Bean> npsBeanList = NPS_Util.Init(dcwjList,dcwj.getYear(),dcwj.getQuarter());
        request.setAttribute("dcwj",dcwj);
        request.setAttribute("npsBeanList",npsBeanList);
        return "/Elite/NPS";
    }
}
